package com.dinzeer.sjapadder.se;

import com.dinzeer.legendreliclib.effect.LReffect;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import com.dinzeer.sjapadder.register.SjaEffect;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.SpecialEffectsRegistry;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;

@Mod.EventBusSubscriber
public class Agitos extends SpecialEffect {
    public Agitos() {
        super(30);
    }
    @SubscribeEvent
    public static void onHitEntity(LivingHurtEvent event) {
        if (event.getSource().getEntity() instanceof LivingEntity attacker) {
            if (attacker.getMainHandItem().getItem() instanceof ItemSlashBlade) {
                List<ResourceLocation> effects = SlashBladeUtil.getState(attacker.getMainHandItem()).getSpecialEffects();

                for (ResourceLocation effectId : effects) {
                    SpecialEffect effect = SpecialEffectsRegistry.REGISTRY.get().getValue(effectId);
                    if (effect instanceof Agitos agitosEffect) {

                        agitosEffect.handleAgitosEffect(event, attacker);
                    }
                }
            }
        }
    }

    private void handleAgitosEffect(LivingHurtEvent event, LivingEntity attacker) {
        LivingEntity target = event.getEntity();
        int ripLevel = 1;
        target.addEffect(new MobEffectInstance(LReffect.TheGreatRip.get(), 20, ripLevel));
         ISlashBladeState state= SlashBladeUtil.getState(attacker.getMainHandItem());
           state.setDamage(-state.getMaxDamage());

        // 处理攻击者身上的DAMAGE_BOOST效果（最大叠加3层）
        MobEffectInstance currentBoost = attacker.getEffect(MobEffects.DAMAGE_BOOST);
        int boostLevel = (currentBoost != null) ? Math.min(currentBoost.getAmplifier() + 1, 2) : 0;
        attacker.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, boostLevel));
    }
}